import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-5, 5, 51)
y = np.cos(x)

plt.rcParams['font.sans-serif'] = 'SimHei'  # 设置字体为SimHei
plt.rcParams['axes.unicode_minus'] = False  # 解决负号“-”显示异常
plt.xlabel('中文x')
plt.ylabel('y')
plt.title("cos曲线-5~5")

plt.plot(x, y, label = 'y=cos(x)')
plt.legend()

plt.savefig('cos.jpg')